<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>热门关键词分析</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            min-height: 100vh;
            padding: 20px;
            color: white;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        header {
            text-align: center;
            padding: 30px 0;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 15px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(5px);
        }
        h1 {
            font-size: 2.8rem;
            margin-bottom: 10px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
            background: linear-gradient(90deg, #ff9966, #ff5e62);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
        }
        .chart-container {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            margin-bottom: 30px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        .chart-title {
            font-size: 1.8rem;
            color: white;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 2px solid #ff9966;
            display: flex;
            align-items: center;
        }
        .chart-title i {
            margin-right: 15px;
            color: #ff9966;
        }
        .chart {
            height: 700px;
            width: 100%;
        }
        .controls {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin: 20px 0;
        }
        .control-group {
            background: rgba(255, 255, 255, 0.15);
            padding: 15px 25px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        label {
            font-size: 1.1rem;
            font-weight: 500;
        }
        input[type="range"] {
            width: 200px;
            height: 8px;
            border-radius: 4px;
            background: rgba(255, 255, 255, 0.2);
            outline: none;
            -webkit-appearance: none;
        }
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #ff9966;
            cursor: pointer;
        }
        .card {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            padding: 20px;
            margin: 20px 0;
            display: flex;
            justify-content: space-around;
            text-align: center;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
        .card-item {
            padding: 15px;
        }
        .card-value {
            font-size: 2.2rem;
            font-weight: bold;
            margin: 10px 0;
            color: #ff9966;
        }
        .card-label {
            font-size: 1.1rem;
            color: rgba(255, 255, 255, 0.8);
        }
        footer {
            text-align: center;
            padding: 20px;
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
            margin-top: 30px;
        }
        @media (max-width: 768px) {
            .chart {
                height: 500px;
            }
            .controls {
                flex-direction: column;
                align-items: center;
            }
            .control-group {
                width: 100%;
                justify-content: space-between;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>热门关键词分析</h1>
            <p class="subtitle">本可视化展示热门关键词的出现频率，帮助您了解用户关注点和产品趋势</p>
        </header>
        
        <div class="card">
            <div class="card-item">
                <div class="card-label">关键词总数</div>
                <div class="card-value" id="totalKeywords">200</div>
            </div>
            <div class="card-item">
                <div class="card-label">最高频关键词</div>
                <div class="card-value" id="topKeyword">set</div>
            </div>
            <div class="card-item">
                <div class="card-label">最高出现次数</div>
                <div class="card-value" id="topCount">41,623</div>
            </div>
        </div>
        
        <div class="controls">
            <div class="control-group">
                <label for="keywordCount">显示数量:</label>
                <input type="range" id="keywordCount" min="10" max="50" value="20">
                <span id="countValue">20</span>
            </div>
            <div class="control-group">
                <label for="minFrequency">最低频率:</label>
                <input type="range" id="minFrequency" min="1000" max="40000" value="1000" step="1000">
                <span id="freqValue">1,000</span>
            </div>
        </div>
        
        <div class="chart-container">
            <h2 class="chart-title"><i class="fas fa-chart-bar"></i> 热门关键词分布</h2>
            <div id="keywordsChart" class="chart"></div>
        </div>
        
        <footer>
            <p>数据来源：热门关键词.json | 最后更新：2025年7月23日</p>
            <p>© 2025 数据分析仪表板 | 使用ECharts可视化库</p>
        </footer>
    </div>

    <script>
        const startTime = performance.now();
                
        // 调用API 
        const response = await fetch(`http://localhost:8080/api/hot-keyword/list?n=200`);
        const result = await response.json();
        const keywordsData = result.data;

        // 更新统计数据
        document.getElementById('totalKeywords').textContent = keywordsData.length;
        document.getElementById('topKeyword').textContent = keywordsData[0][0];
        document.getElementById('topCount').textContent = keywordsData[0][1].toLocaleString();

        // 初始化图表
        const chartDom = document.getElementById('keywordsChart');
        const myChart = echarts.init(chartDom);
        
        // 准备数据
        function prepareData(count, minFreq) {
            // 过滤数据
            const filteredData = keywordsData.filter(item => item[1] >= minFreq);
            
            // 排序并取前N个
            const sortedData = [...filteredData].sort((a, b) => b[1] - a[1]);
            const topData = sortedData.slice(0, count);
            
            // 提取关键词和频率
            const keywords = topData.map(item => item[0]);
            const frequencies = topData.map(item => item[1]);
            
            return { keywords, frequencies };
        }
        
        // 渲染图表
        function renderChart(count = 20, minFreq = 1000) {
            const { keywords, frequencies } = prepareData(count, minFreq);
            
            const option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    },
                    formatter: '{b}: {c}'
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    name: '出现次数',
                    axisLabel: {
                        formatter: function(value) {
                            return (value / 1000).toFixed(0) + 'K';
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.1)'
                        }
                    }
                },
                yAxis: {
                    type: 'category',
                    data: keywords,
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.5)'
                        }
                    },
                    axisLabel: {
                        interval: 0,
                        fontSize: 12,
                        color: 'rgba(255, 255, 255, 0.9)'
                    }
                },
                series: [
                    {
                        name: '出现次数',
                        type: 'bar',
                        data: frequencies,
                        itemStyle: {
                            color: function(params) {
                                const colorList = [
                                    '#FF6B6B', '#FF8E53', '#FFCE63', '#4ECDC4', '#556270',
                                    '#36D1DC', '#5B86E5', '#834d9b', '#d74177', '#00467F',
                                    '#A5CC82', '#FFD700', '#FF6347', '#00CED1', '#9370DB'
                                ];
                                return colorList[params.dataIndex % colorList.length];
                            }
                        },
                        label: {
                            show: true,
                            position: 'right',
                            formatter: '{c}',
                            color: 'rgba(255, 255, 255, 0.9)'
                        }
                    }
                ]
            };

            myChart.setOption(option);
        }
        
        // 初始渲染
        renderChart();
        
        // 添加交互控制
        const countSlider = document.getElementById('keywordCount');
        const freqSlider = document.getElementById('minFrequency');
        const countValue = document.getElementById('countValue');
        const freqValue = document.getElementById('freqValue');
        
        countSlider.addEventListener('input', function() {
            countValue.textContent = this.value;
            renderChart(parseInt(this.value), parseInt(freqSlider.value));
        });
        
        freqSlider.addEventListener('input', function() {
            freqValue.textContent = parseInt(this.value).toLocaleString();
            renderChart(parseInt(countSlider.value), parseInt(this.value));
        });
        
        // 响应式调整
        window.addEventListener('resize', function() {
            myChart.resize();
        });
    </script>
    
    <!-- Font Awesome 图标 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
</body>
</html>